package com.tjp.subject.domain.handler.subject;

import com.tjp.subject.common.enums.SubjectInfoTypeEnum;
import com.tjp.subject.domain.convert.SubjectJudgeConverter;
import com.tjp.subject.domain.entity.SubjectInfoBO;
import com.tjp.subject.domain.entity.SubjectOptionBO;
import com.tjp.subject.infra.basic.entity.SubjectJudge;
import com.tjp.subject.infra.basic.service.SubjectJudgeService;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;
import java.util.LinkedList;
import java.util.List;

/**
 * @program: jz-club
 * @description: 判断抽象接口策略类
 * @author: aaronTang
 * @create: 2024-02-29
 */
@Component
public class JudgeTypeHandler implements SubjectTypeHandler {

    @Resource
    private SubjectJudgeService subjectJudgeService;

    @Override
    public SubjectInfoTypeEnum getHandlerType() {
        return SubjectInfoTypeEnum.JUDGE;
    }

    @Override
    public void add(SubjectInfoBO subjectInfoBO) {
        //实际往表中插入判断题的逻辑
        List<SubjectJudge> subjectJudgeList = new LinkedList<>();

        subjectInfoBO.getOptionList().forEach(option -> {
            //option转换为SubjectJudge
            SubjectJudge subjectJudge = SubjectJudgeConverter.INSTANCE.convertBOToJudgeEntity(option);
            //填充题目id
            subjectJudge.setSubjectId(subjectInfoBO.getId());
            subjectJudgeList.add(subjectJudge);
        });

        subjectJudgeService.batchInsert(subjectJudgeList);
    }

    @Override
    public SubjectOptionBO query(Long subjectId) {
        return null;
    }
}
